package com.wangtao.firstapp.adapters;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;
import com.wangtao.firstapp.R;
import com.wangtao.firstapp.activity.AuthorCollectSingleGoodActivity;
import com.wangtao.firstapp.activity.ShopDetailsActivity;
import com.wangtao.firstapp.modles.OriginalAuthorCollect;

import java.util.List;

/**
 *  用户作者  介绍页面（收藏—>单品）单品适配器
 * Created by lanouhn on 16/9/7.
 */
public class AuthorCollectOneAdapter extends RecyclerView.Adapter<AuthorCollectOneAdapter.CollectOneViewHolder>{

    private Context context;
    private List<OriginalAuthorCollect.DataBean.ProductBean> productBean;

    public AuthorCollectOneAdapter(Context context, List<OriginalAuthorCollect.DataBean.ProductBean> productBean) {
        this.context = context;
        this.productBean = productBean;
    }

    @Override
    public CollectOneViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(context).inflate(R.layout.item_mygridview4,null);
        CollectOneViewHolder holder=new CollectOneViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(CollectOneViewHolder holder, final int position) {


        Picasso.with(context).load(productBean.get(position).getPic()).into(holder.imagview);

        //跳转至，单品详情页面
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (productBean.get(position).getProduct_type().equals("")){
                    String shop_ID = productBean.get(position).getId();
                    Intent intent=new Intent(context, AuthorCollectSingleGoodActivity.class);
                    intent.putExtra("shop_iD",shop_ID);
                    context.startActivity(intent);
                }else if (productBean.get(position).getProduct_type().equals("6")){
                    String shop_ID = productBean.get(position).getId();
                    Intent intent=new Intent(context, ShopDetailsActivity.class);
                    intent.putExtra("shop_iD",shop_ID);
                    context.startActivity(intent);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return productBean.size();
    }

    public class CollectOneViewHolder extends RecyclerView.ViewHolder {

       private ImageView imagview;
       public CollectOneViewHolder(View itemView) {
           super(itemView);
           imagview= (ImageView) itemView.findViewById(R.id.iv_item_mygridview4);
       }
   }



}
